//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by FernFlower decompiler)
//

package org.springframework.remoting.httpinvoker;

import java.io.FilterOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.OutputStream;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.remoting.rmi.RemoteInvocationSerializingExporter;
import org.springframework.remoting.support.RemoteInvocation;
import org.springframework.remoting.support.RemoteInvocationResult;
import org.springframework.web.HttpRequestHandler;
import org.springframework.web.util.NestedServletException;

/** @deprecated */
@Deprecated
public class HttpInvokerServiceExporter extends RemoteInvocationSerializingExporter implements HttpRequestHandler {
    public HttpInvokerServiceExporter() {
    }

    public void handleRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
//        try {
//            RemoteInvocation invocation = this.readRemoteInvocation(request);
//            RemoteInvocationResult result = this.invokeAndCreateResult(invocation, this.getProxy());
//            this.writeRemoteInvocationResult(request, response, result);
//        } catch (ClassNotFoundException var5) {
//            throw new NestedServletException("Class not found during deserialization", var5);
//        }
    }

    protected RemoteInvocation readRemoteInvocation(HttpServletRequest request) throws IOException, ClassNotFoundException {
        return this.readRemoteInvocation(request, request.getInputStream());
    }

    protected RemoteInvocation readRemoteInvocation(HttpServletRequest request, InputStream is) throws IOException, ClassNotFoundException {
        ObjectInputStream ois = this.createObjectInputStream(this.decorateInputStream(request, is));
        Throwable var4 = null;

        RemoteInvocation var5;
        try {
            var5 = this.doReadRemoteInvocation(ois);
        } catch (Throwable var14) {
            var4 = var14;
            throw var14;
        } finally {
            if (ois != null) {
                if (var4 != null) {
                    try {
                        ois.close();
                    } catch (Throwable var13) {
                        var4.addSuppressed(var13);
                    }
                } else {
                    ois.close();
                }
            }

        }

        return var5;
    }

    protected InputStream decorateInputStream(HttpServletRequest request, InputStream is) throws IOException {
        return is;
    }

    protected void writeRemoteInvocationResult(HttpServletRequest request, HttpServletResponse response, RemoteInvocationResult result) throws IOException {
        response.setContentType(this.getContentType());
        this.writeRemoteInvocationResult(request, response, result, response.getOutputStream());
    }

    protected void writeRemoteInvocationResult(HttpServletRequest request, HttpServletResponse response, RemoteInvocationResult result, OutputStream os) throws IOException {
        ObjectOutputStream oos = this.createObjectOutputStream(new HttpInvokerServiceExporter.FlushGuardedOutputStream(this.decorateOutputStream(request, response, os)));
        Throwable var6 = null;

        try {
            this.doWriteRemoteInvocationResult(result, oos);
        } catch (Throwable var15) {
            var6 = var15;
            throw var15;
        } finally {
            if (oos != null) {
                if (var6 != null) {
                    try {
                        oos.close();
                    } catch (Throwable var14) {
                        var6.addSuppressed(var14);
                    }
                } else {
                    oos.close();
                }
            }

        }

    }

    protected OutputStream decorateOutputStream(HttpServletRequest request, HttpServletResponse response, OutputStream os) throws IOException {
        return os;
    }

    private static class FlushGuardedOutputStream extends FilterOutputStream {
        public FlushGuardedOutputStream(OutputStream out) {
            super(out);
        }

        public void flush() throws IOException {
        }
    }
}
